import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        userInfo: {
            token: '',
            username: '游客',
            power: '0',
            id: null,
            img: ''
        }
    },
    getters: {
        getUserInfo: (state) => {
            return state.userInfo
        }
    },
    mutations: {
        setUserInfo: (state, obj) => {
            state.userInfo = {...state.userInfo, ...obj}
            localStorage.setItem('userInfo', JSON.stringify(state.userInfo))
        }
    },
    actions: {},
})
